<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
        .uploader-list {
            margin-left: -15px;
        }

        .uploader-list .info {
            position: relative;
            margin-top: -25px;
            background-color: black;
            color: white;
            filter: alpha(Opacity=80);
            -moz-opacity: 0.5;
            opacity: 0.5;
            width: 100px;
            height: 25px;
            text-align: center;
            display: none;
        }

        .uploader-list .handle {
            position: relative;
            background-color: black;
            color: white;
            filter: alpha(Opacity=80);
            -moz-opacity: 0.5;
            opacity: 0.5;
            width: 120px;
            text-align: right;
            height: 18px;
            margin-bottom: -18px;
            display: none;
        }

        .uploader-list .handle i {
            margin-right: 5px;
        }

        .uploader-list .handle i:hover {
            cursor: pointer;
        }

        .uploader-list .file-iteme {
            margin: 12px 0 0 15px;
            padding: 1px;
            float: left;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
	<div class="layui-form-item" style="width:800px;">
		<input type="hidden" value="${expert.id?default('')}" name="id" id="id"/>
        <label class="layui-form-label required">专家名称</label>
        <div class="layui-input-block">
            <input type="text" name="exportName" lay-verify="required" lay-reqtext="专家名称不能为空" placeholder="请输入专家名称" value="${expert.exportName?default('')}" class="layui-input">            
        </div>
    </div>
    <div class="layui-form-item">
     	<label class="layui-form-label required">个人照片</label>
	   <div class="layui-upload layui-inline">
		    <div class="layui-upload-list uploader-list">
			    <div id="" class="file-iteme">
			    	<div class="handle" id="handle1"><i class="layui-icon layui-icon-delete"></i></div>
			        <img class="layui-upload-img" src="" onerror="this.src='../images/img.png'" id="demo1" style="width:120px;height:120px">
			    </div>
		    </div>
		    <button type="button" class="layui-btn" id="test1" style="width:120px;">上传个人照片</button>
		    <input type="hidden" name="exportPic" id="demoText1" lay-verify="required" lay-reqtext="请上传个人照片" />
	   </div>
	</div>
	<div class="layui-form-item" style="width:800px;">
        <label class="layui-form-label required">教育背景</label>
        <div class="layui-input-block">
	      	<select name="educationalBackground" id="educationalBackground" lay-search="" lay-filter="educationalBackground" lay-verify="required" lay-reqtext="请选择教育背景">
	      	</select>
	    </div>
    </div>
    <div class="layui-form-item" style="width:800px;">
        <label class="layui-form-label required">毕业院校</label>
        <div class="layui-input-block">
            <input type="text" name="schoolName" lay-verify="required" lay-reqtext="毕业院校不能为空" placeholder="请输入毕业院校" value="${expert.schoolName?default('')}" class="layui-input">            
        </div>
    </div>
   <div class="layui-form-item" style="width:800px;">
        <label class="layui-form-label required">技术领域</label>
        <div class="layui-input-block">
	      	<select name="technicalField" id="technicalField" lay-search="" lay-filter="technicalField" lay-verify="required" lay-reqtext="请选择技术领域">
	      	</select>
	    </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">性别</label>
        <div class="layui-input-block">
        <#if expert.sex ='0' >
	        <input type="radio" name="sex" value="0" title="男" checked="">
            <input type="radio" name="sex" value="1" title="女">
        </#if>
    	<#if expert.sex = '1'>
	        <input type="radio" name="sex" value="0" title="男">
            <input type="radio" name="sex" value="1" title="女" checked="">
        </#if>
        </div>
    </div>
    <div class="layui-form-item" style="width:800px;">
        <label class="layui-form-label required">工作单位</label>
        <div class="layui-input-block">
            <input type="text" name="workName" lay-verify="required" lay-reqtext="工作单位不能为空" placeholder="请输入工作单位" value="${expert.workName?default('')}" class="layui-input">            
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            <button class="layui-btn layui-btn-normal" onclick="javascript :window.history.go(-1)">返回</button>
        </div>
    </div>
</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','upload'], function () {
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload,
            $ = layui.$;
        
        layer.ready(function(){
        	$('#demo1').attr('src', "${expert.exportPic?default('')}");
            $('#demoText1').val("${expert.exportPic?default('')}");	
            
        	$.ajax({
                type : "POST",
                url : "../parameter/getParameter",
                contentType: "application/json;charset=utf-8",
                data : JSON.stringify({"parameterType":"educational"}),
                dataType: "json",
                success : function(result) {
	    		    var data=result.data;
	    		    var info = "<option value=''>请选择</option>";
	    		    for (var i = 0; i < data.length; i++) {
		    		    if(data[i].id != "${expert.educationalBackground?default('')}"){
	    		        	info += "<option value=" + data[i].id + ">" + data[i].parameterName + "</option>";
	    		    	}else{
	    		    		info += "<option value=" + data[i].id + " selected='selected'>" + data[i].parameterName + "</option>";
	    		    	}
	    		    }
	    		    $("#educationalBackground").append(info);
	    		    form.render('select');
                }
 			});
        	
        	$.ajax({
                type : "POST",
                url : "../parameter/getParameter",
                contentType: "application/json;charset=utf-8",
                data : JSON.stringify({"parameterType":"technical"}),
                dataType: "json",
                success : function(result) {
	    		    var data=result.data;
	    		    var info = "<option value=''>请选择</option>";
	    		    for (var i = 0; i < data.length; i++) {
		    		    if(data[i].id != "${expert.technicalField?default('')}"){
	    		        	info += "<option value=" + data[i].id + ">" + data[i].parameterName + "</option>";
	    		    	}else{
	    		    		info += "<option value=" + data[i].id + " selected='selected'>" + data[i].parameterName + "</option>";
	    		    	}
	    		    }
	    		    $("#technicalField").append(info);
	    		    form.render('select');
                }
 			});        	
        });
        
      //监听提交
        form.on('submit(saveBtn)', function (data) {  	   		   
        	$.ajax({
                type : "POST", //提交方式
                url : "update",//路径
                contentType: "application/json;charset=utf-8",
                data : JSON.stringify(data.field),//数据，这里使用的是Json格式进行传输
                dataType: "json",
                success : function(result) {//返回数据根据结果进行相应的处理
                    if (result.code == "200") {
                        var index = layer.msg("修改成功", {
                            time: 1000, //如果不配置，默认是3秒）
                        },function () {
                        	// 关闭弹出层
                        	layer.close(index);
                        	window.open('detail','_self');
                        })
                    }else{
                        layer.msg(result.msg);
                    }
                }
            });
            return false;
        });
   	 	
   	 var uploadurl=localStorage.getItem("uploadurl");
     //图片上传上传
       var loading;
       var uploadInst = upload.render({
           elem: '#test1'
           ,accept: 'images' //普通文件
           ,url: uploadurl+'/hnyfkj-file-server/common/upload' //改成您自己的上传接口
           ,before: function(obj){
       		loading= layer.msg('正在上传,请稍后', {icon: 16, shade: 0.3, time:0});
               //预读本地文件示例，不支持ie8
               obj.preview(function(index, file, result){
                   $('#demo1').attr('src', result); //图片链接（base64）
               });
           }
           ,choose: function(obj){
               var param = $('input[name="file"]')[0].value.toString();
               var params = param.split("\.");
               var name = params[0].split("\\");
				var iname = name[name.length-1].replace(/,/, "");
               this.data={name:name[name.length-1].replace(/,/, ""),type:"."+params[params.length-1],system:"im"}
               console.log(this.data);
           }
           ,data: {}
           ,done: function(res){
       		layer.close(loading);
               //如果上传失败
               $("#demoText1").val(uploadurl+"/"+res.result);
               if(res.code != 200){
                   return layer.msg('上传失败');
               }
               //上传成功
           }
           ,error: function(){
               //演示失败状态，并实现重传
               var demoText = $('#demoText1');
               demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
               demoText.find('.demo-reload').on('click', function(){
                   uploadInst.upload();
               });
           }
       });
       
       //删除图片
       $(document).on("mouseenter mouseleave", ".file-iteme", function(event){
           if(event.type === "mouseenter"){
               //鼠标悬浮
               $(this).children(".info").fadeIn("fast");
               $(this).children(".handle").fadeIn("fast");
           }else if(event.type === "mouseleave") {
               //鼠标离开
               $(this).children(".info").hide();
               $(this).children(".handle").hide();
           }
       });

    	// 删除图片
       $(document).on("click", "#handle1", function(event){
       	$('#demo1').attr('src', "");
       	$('#demoText1').val("");
       });
    });
</script>
</body>
</html>